<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;

class TaskExport implements FromCollection, WithHeadings, WithColumnWidths, WithEvents
{
    protected $data;

    public function __construct(Collection $data)
    {
        $this->data = $data;
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        return [
            '车辆类型',
            '内陆司机',
            '香港司机',
            '车辆服务提供商',
            '车牌',
            '装车地',
            '卸货点',
            '关场口岸',
            '装车日期',
            '大包件数',
            '重量'
        ];

    }

    public function columnWidths(): array
    {
        // 设置每列的宽度
        return [
            'A' => 30,
            'B' => 50,
            'C' => 50,
            'D' => 50,
            'E' => 20,
            'F' => 30,
            'G' => 30,
            'H' => 30,
            'I' => 30,
            'J' => 20,
            // 根据你的需求设置其他列的宽度
        ];
    }

    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $event->sheet->getDelegate()->freezePane('A2');
            },
        ];
    }

}